package main;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.GameCanvas;

import control.ControlCommand;
import control.DrawButton;
import control.Panel;
import control.TextControl;

public class OptionCanvas extends GameCanvas {
	protected Panel panel;
	protected DrawButton soundButton;
	protected final MainMidlet game;
	//protected Image background;

	protected OptionCanvas(MainMidlet midlet) {
		super(true);
		this.game = midlet;
		setFullScreenMode(true);
		panel = new Panel(20, 20, 200, 360, 3);
		panel.setControl(0, new TextControl("Sound", 30, 30));
		soundButton = new DrawButton(-1, 160, 25, 50, 30, "OFF");
		soundButton.setCommand(new ControlCommand() {
			public void Do() {
				soundButton.toggled();
				if(soundButton.isToggled()){
					soundButton.setText("ON");
				}else{
					soundButton.setText("OFF");
				}
				Res.soundOn = soundButton.isToggled();
			}
		});
		if(Res.soundOn){
			soundButton.toggled();
			soundButton.setText("ON");
		}
		panel.setControl(1, soundButton);
		panel.setControl(2, new DrawButton(-1, 160, 340, 60, 40, "BACK"));
		panel.get(2).setCommand(new ControlCommand() {
			public void Do() {
				game.showMenuCanvas();
			}
		});
	}

	protected void pointerPressed(int x, int y) {
		panel.pointerPressed(x, y);
		repaint();
	}

	protected void pointerReleased(int x, int y) {
		panel.pointerReleased(x, y);
		repaint();
	}

	protected void pointerDragged(int x, int y) {
		panel.pointerPressed(x, y);
		repaint();
	}

	public void paint(Graphics g) {
	//	g.drawImage(background, 0, 0, 0);
		g.setColor(0x886600);
		g.fillRect(0, 0, 240, 400);
		panel.paint(g);
	}
}